# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gedit
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.34.0
pkgrel=2
arch=('any')
pkgdesc="A text editor for GNOME (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-appstream-glib"
         "${MINGW_PACKAGE_PREFIX}-enchant"
         "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-gtksourceview4"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-iso-codes"
         "${MINGW_PACKAGE_PREFIX}-libpeas"
         "${MINGW_PACKAGE_PREFIX}-libsoup"
         "${MINGW_PACKAGE_PREFIX}-python3-gobject"
         "${MINGW_PACKAGE_PREFIX}-gspell"
         "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-gettext"
             "${MINGW_PACKAGE_PREFIX}-itstool"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-yelp-tools")
options=('strip' 'staticlibs')
license=("GPL")
url="https://www.gnome.org"
install=${_realname}-${CARCH}.install
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        'skip-loading-private.patch'
        'missing-schema.patch')
sha256sums=('3e95e51d3ccb495a9ac95aa3ed7fe8fe37ccde7c678f37fa3cea684bc71d507e'
            'f9b534f0ff5139e4f75526b610ba6965e73e5704e5fd7969dd30436c74aa5f43'
            '32d7636de53e5e2e1cfa35a45c60bf32660ce2e1e48471d50cb6df570dbaa36f')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -Np1 -i "${srcdir}"/skip-loading-private.patch
  patch -Np1 -i "${srcdir}"/missing-schema.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  ${MINGW_PREFIX}/bin/meson \
    --buildtype=plain \
    -Dintrospection=true \
    -Dvapi=true \
    -Dplugins=true \
    -Ddocumentation=true \
    -Denable-gvfs-metadata=auto \
    "../${_realname}-${pkgver}"

  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

  mv "${pkgdir}${MINGW_PREFIX}"/lib/gedit/*.dll "${pkgdir}${MINGW_PREFIX}"/bin

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
